package cashRegister;

// Totals up sales and compute change due.
public class cashRegister {

	// Creates variables shared between methods
	
	private double purchase;
	private double payment;
	private double $$$stash = 0;
	private double governmentMooch;
	private double itemsSold;
	
	// Creates a new cashRegister instance with no money and sets a global tax (in percent)
	
	public cashRegister(double tax)
	{
		
		governmentMooch = tax / 100;
	}
	
	
	//Records the sale of an item.
	
	public void recordPurchase(double ntamount)
	{
		purchase = purchase + ntamount;
		$$$stash = $$$stash + ntamount;
		itemsSold++;
	}
	
	// Records the sale of a taxable item
	
	public void recordTaxablePurchase(double tamount)
	{
		purchase = purchase + (tamount + (tamount * governmentMooch));
		$$$stash = $$$stash + (tamount + (tamount * governmentMooch));
		itemsSold++;
	}
	
	// Enters the payment received from the customer.
	
	public void enterPayment(double amount)
	{
		payment = amount;
		
	}
	
	
	// Computes the change due and resets the machine for next customer.
	
	public double giveChange()
	{
		double change = Math.round((payment - purchase) * 100.0) / 100.0;
		purchase = 0;
		payment = 0;
		return change;
	}
	
	// Gets the total sales for the day
	
	public double getSalesTotal()
	{
		return $$$stash;
	}
	
	// Gets the total items sold for the day
	
	public double getItemsSold()
	{
		return itemsSold;
	}
	
	// Resets daily Records
	
	public void reset()
	{
		itemsSold = 0;
		$$$stash = 0;
	}
}